import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { getSetting } from '@/api'

export const useSettingStore = defineStore('setting', () => {
  let initedSettingList = ref(false)
  let setting = ref({})
  let nearest_store = ref({})
  const initSettingListByStore =async () => {
    
    if (!initedSettingList.value) {
      
      return new Promise((resolve, reject) => {
        getSetting().then((res) => {

          let r = {}
          res.pages_config.forEach(el=>{
            r[el.page_url] = {share_cover_url:el.share_cover_url,share_title:el.share_title,banner_url:el.banner_url}
          })
          res.pages_share_cover_map  =r
          setting.value = res
        
          initedSettingList.value = true
          // debugger
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    }else{
      return Promise.resolve(setting.value)
    }
  }
  return { setting, initSettingListByStore ,nearest_store}
})

